<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>数据查看</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">

                </div>
                <div id="toolbar" class="row">
                    <button id="btn_getData" class="btn btn-success">获取数据</button>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>

<div th:include="include :: footer"></div>

<script th:inline="javascript">
    let table;
    $(function () {
        /**
         * 加载列表
         */
        table = js.table.init({
            url: ctx + "getData/list",
            showColumns: true,
            showExport: true,
            columns: [
                // {
                //     title:'<input class="checkboxAll"  type="checkbox" onclick="selectedAll()" >',width: '40',
                //     formatter: function (value, row, index) {
                //         if (row.quoteStatus == 0 && row.budgetProcessStatus == 3) {
                //             return '<input class="checkbox_select"  type="checkbox" name= "checkbox_select" value="' + $('<div/>').text(row.quoteTaskId).html() + '">';
                //         } else {
                //             return "";
                //         }
                //     }
                // },
                {
                    title: '序号', field: 'id', width: '60',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {title: '物料描述', field: 'matDesc'},
                {title: '数量', field: 'num'},
                {title: '单位', field: 'unit'},
                {title: '单价', field: 'price'},
                {
                    title: '金额',
                    formatter: function (value, row, index) {
                        if (row.price != null) {
                            return row.num * row.price;
                        } else {
                            return '--';
                        }
                    }
                }
            ]
        });


        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });

        /**
         * 模态框隐藏事件， 重置表单，重置验证
         */
        js.modal.hideEvent("modal-edit", function () {
            js.validate.reset("halfAdjEditForm");
            js.reset("halfAdjEditForm");
        });
        /**
         * 获取数据
         */
        $("#btn_getData").click(function () {
            js.post({
                url: ctx + 'getData/getMatData',
                type: 'post',
                traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                dataType: 'json',
                contentType: "application/x-www-form-urlencoded",
                data: {

                },
                async: true,                // 异步执行
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                },
                error: function () {
                    js.modal.fail();
                }

            });
        });
    });
</script>
</body>
</html>